<?php
/**
 * Created by PhpStorm.
 * User: 11893
 * Date: 2018/10/19
 * Time: 14:34
 */

namespace App\Models;


use Carbon\Carbon;
use Illuminate\Database\Eloquent\Model;

class Activity extends Model
{
    protected $table = 'activities';

    protected $fillable = ['title','product_id', 'type', 'quantity', 'start_time', 'end_time', 'status'];

    protected $casts = [
      'status'=> 'boolean'
    ];

    public function activity()
    {
        return $this->hasMany(Booking::class);
    }

    public function product()
    {
        return $this->belongsTo(Product::class);
    }

    public function checkIsOver()
    {
        return !$this->status || Carbon::now()->gt($this->end_time);
    }

}